import json
class Config:
    def __init__(self, config_file="config.json"):
        self.config_file = config_file
        self.config = self.load_config()

    def load_config(self):
        try:
            with open(self.config_file, 'r', encoding='utf-8') as f:
                return json.load(f)
        except FileNotFoundError:
            print(f"配置文件 {self.config_file} 不存在，使用默认配置")
            return self.get_default_config()
        except json.JSONDecodeError:
            print(f"配置文件 {self.config_file} 格式错误，使用默认配置")
            return self.get_default_config()

    def get_default_config(self):
        return {
            "minio": {
                "endpoint": "8.137.58.206:9000",
                "access_key": "9eBv4Rt6",
                "secret_key": "3a7W5Mz8",
                "secure": True,
                "bucket_name": "bucket1"
            },
            "watch_path": "/home/nvidia/Downloads/PYPRO/test_folder/",
            "logging": {
                "log_dir": "logs",
                "log_level": "INFO"
            },
            "file_monitor": {
                "extensions": [".jpg", ".png", ".jpeg", ".bmp"],
                "stable_check_interval": 1,
                "max_stable_wait": 10,
                "max_retries": 3
            }
        }

    def get_minio_config(self):
        return self.config.get("minio", {})

    def get_watch_path(self):
        """获取监控路径"""
        return self.config.get("watch_path", "/tmp/")

    def get_logging_config(self):
        """获取日志配置"""
        return self.config.get("logging", {})

    def get_file_monitor_config(self):
        """获取文件监控配置"""
        return self.config.get("file_monitor", {})

    def get_watch_paths(self):
        """监控多个文件夹的路径"""
        return self.config.get("watch_paths", [])

